package com.aaa;

import com.aaa.R;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.view.Menu;
//import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


import android.content.DialogInterface;


public class Main extends Activity {
    /** Called when the activity is first created. */
	final Context context = this;
	String result="";
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
 
				
        final EditText et1 = (EditText) findViewById(R.id.editText1);
        final EditText et2 = (EditText) findViewById(R.id.editText2);
        Button b = (Button) findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				//Intent intent = new Intent(Main.this, Second.class);
				try
				{
					result=""+(Integer.parseInt(et1.getText().toString())+Integer.parseInt(et2.getText().toString()));
				//intent.putExtra("thetext","Resultado: "+(Integer.parseInt(et1.getText().toString())+Integer.parseInt(et2.getText().toString())));
				}
				catch(Exception e)
				{
					//intent.putExtra("thetext","Resultado: METE NUMEROS");
					result="METE NUMEROS";
				}
//				startActivity(intent);
				// create alert dialog
				AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
				// set title
				alertDialogBuilder.setTitle("Resultado");
	 
				// set dialog message
				alertDialogBuilder
					.setMessage(result)
					.setCancelable(false)
					.setPositiveButton("OK",new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,int id) {
							// if this button is clicked, close
							// current activity
						}
					  });
				AlertDialog alertDialog = alertDialogBuilder.create();
 
				// show it
				alertDialog.show();
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    
}
